Skip to content

chore: Adds Knative Cloud Events KB#57

Merged
tik-seven merged 1 commit intomainfrom
chore/move-knative-kb
Sep 10, 2025
Merged

chore: Adds Knative Cloud Events KB#57
tik-seven merged 1 commit intomainfrom
chore/move-knative-kb

Conversation

@danielfbm
Copy link
Copy Markdown
Member

@danielfbm danielfbm commented Sep 9, 2025

Summary by CodeRabbit

  • Documentation

    • Added an end-to-end guide for publishing and consuming CloudEvents with Knative Eventing in ACP, covering broker/source setup, consumer apps, Spring Boot producer/consumer examples, deployment manifests, testing steps, and advanced routing/filtering with dead-letter queues.
  • Chores

    • Updated ignore rules to exclude macOS system files and preserve existing build output ignores; fixed end-of-file newline.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 9, 2025

Walkthrough

Adds .DS_Store to .gitignore and fixes EOF newline. Adds a new English documentation guide describing end-to-end CloudEvents publishing and consuming with Knative Eventing, including setup, YAML manifests, Spring Boot examples, routing/filtering, and testing steps.

Changes

Cohort / File(s) Summary of Changes
Repo housekeeping
\.gitignore
Added .DS_Store ignore entry; fixed end-of-file newline. (dist remains ignored.)
Documentation: Knative Eventing guide
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md
Added a comprehensive guide covering Knative Eventing concepts, Broker/Trigger setup, event sources, consumer app examples, Spring Boot CloudEvents publisher/consumer code samples, Kubernetes manifests, testing steps, and advanced routing/filtering (including DLQ).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Client
  participant Publisher as Spring Boot Publisher
  participant Broker as Knative Broker
  participant Trigger as Knative Trigger
  participant Consumer as Event Consumer
  participant DLQ as Dead-Letter Sink

  Note over Client,Consumer: High-level CloudEvents flow from the new documentation

  Client->>Publisher: HTTP request → trigger publish
  Publisher->>Broker: HTTP POST CloudEvent
  Broker-->>Broker: Validate & fan-out
  Broker->>Trigger: Evaluate filters
  alt Trigger matches
    Trigger->>Consumer: Deliver CloudEvent (HTTP POST)
    Consumer-->>Broker: 2xx ACK
  else No match or delivery failure
    Broker->>DLQ: Route to DLQ (if configured)
    DLQ-->>Broker: ACK
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • black89757

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request currently lacks a description and does not provide any context or summary of the changes made, making it difficult for reviewers to understand its purpose. Please add a clear description that outlines the objectives of this pull request, including details about the new Knative Cloud Events documentation and the .gitignore update, as well as the motivation for these changes to aid in the review process.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change by indicating the addition of a Knative Cloud Events knowledge base entry, which aligns with the main content added in this pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I hop through lines and YAML bright,
Brokers hum and triggers bite.
Publishers toss CloudEvents true,
Consumers nibble payload stew.
.DS_Store hidden, dist tucked away—hop, hop, hooray! 🥕

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/move-knative-kb

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (9)
.gitignore (1)

15-16: Be explicit about directory ignore and broaden .DS_Store pattern

Use a trailing slash to avoid matching files named “dist”, and ignore .DS_Store everywhere.

- dist
-.DS_Store
+ dist/
+ **/.DS_Store
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (8)

128-149: Nit: fix wording and pin image

Minor grammar and supply-chain hygiene.

- # Change to inhouse registry address and image
+ # Change to your in-house registry address and pin the image by digest
- image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display
+ image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display@sha256:<digest>

200-205: Clarify Trigger filters syntax vs. API version

Knative supports both legacy spec.filter.attributes and newer spec.filters forms depending on version. Document the target version and stick to one form throughout to avoid confusion.


363-369: Fix typos and phrasing

Small editorial cleanups.

-For this part we will still build uppon the EventConsumer created on the last part.
+For this part, we will build upon the EventConsumer created in the previous section.

559-574: Prefer env var over hard-coded default

Given you already set KNATIVE_BROKER_URL in the Deployment, avoid baking a cluster-specific default in code.

-    url: http://broker-ingress.knative-operator.svc.cluster.local/my-app-namespace/default
+    url: ${KNATIVE_BROKER_URL}

695-705: Clarify service address for curl

Kubernetes Service isn’t externally accessible by default. Suggest using the in-cluster DNS name or port-forwarding for testing.

-Change the address to its full qualified URL and try the API:
+From inside the cluster, use: http://springboot-event-app.my-app-namespace.svc.cluster.local/api/users
+For local testing, first run: kubectl -n my-app-namespace port-forward svc/springboot-event-app 8080:80
+Then curl: http://localhost:8080/api/users

711-727: Trigger filter form inconsistent with earlier examples

Earlier you used spec.filters; here you switched to spec.filter.attributes. Please standardize to one form for the targeted Knative version.


56-61: Editorial fixes for consistency and typos

Quick pass to improve readability and consistency (CloudEvents, Spring Boot, etc.).

- The following steps uses `Alauda DevOps Eventing v3` plugin
+ The following steps use the `Alauda DevOps Eventing v3` plugin
- Lets create a simple HTTP service that receives and output events as logs:
+ Let's create a simple HTTP service that receives events and outputs them as logs:
- ## Chapter 3. Enabling SpringBoot Applications for Cloud Events
+ ## Chapter 3. Enabling Spring Boot Applications for CloudEvents
-     com.example: DEBUG
+     com.example: DEBUG
- ### Testing the SpringBoot Application
+ ### Testing the Spring Boot Application
- And our main entrypoint
+ Main application entry point

Also, the document jumps from Chapter 3 to Chapter 5; renumber or add the missing Chapter 4.

Also applies to: 128-129, 239-239, 571-574, 695-695, 803-805


207-207: Add link label punctuation

Grammar nit.

-For a more detailed reference on Triggers, refer to the [Knative documentation](https://knative.dev/docs/eventing/triggers/).
+For a more detailed reference on Triggers, refer to the [Knative documentation](https://knative.dev/docs/eventing/triggers/).
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 816129b and c74d683.

⛔ Files ignored due to path filters (3)
  • docs/public/KB250700002/knative-eventing.png is excluded by !**/*.png
  • package-lock.json is excluded by !**/package-lock.json
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md

28-28: Images should have alternate text (alt text)

(MD045, no-alt-text)


750-750: Hard tabs
Column: 1

(MD010, no-hard-tabs)


751-751: Hard tabs
Column: 1

(MD010, no-hard-tabs)


752-752: Hard tabs
Column: 1

(MD010, no-hard-tabs)


753-753: Hard tabs
Column: 1

(MD010, no-hard-tabs)

🔇 Additional comments (2)
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (2)

809-814: Validate external references

Double-check that all referenced docs/URLs are still current and accessible; consider pinning to specific versions if needed.


85-93: Verify broker URL discovery command
Confirm that kubectl get broker default -n my-app-namespace -o jsonpath='{.status.address.url}' successfully returns the broker URL in your environment (ensure kubectl is installed, your context is set, and the namespace is correct) before replacing hard-coded URLs.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (4)
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (4)

28-28: Add descriptive alt text to the image

Image is missing alt text; keep current path and add a concise description.

-![](/KB250700002/knative-eventing.png)
+![Knative Eventing architecture](/KB250700002/knative-eventing.png)

281-322: Null-safe data logging, charset, and remove unused import

Avoid NPE when data is absent, specify UTF-8, and drop an unused import.

 import io.cloudevents.http.HttpMessageFactory;
-import io.cloudevents.jackson.JsonFormat;
+import java.nio.charset.StandardCharsets;
@@
-            logger.info("  Data: {}", new String(event.getData().toBytes()));
+            if (event.getData() != null) {
+                logger.info("  Data: {}", new String(event.getData().toBytes(), StandardCharsets.UTF_8));
+            } else {
+                logger.info("  Data: <none>");
+            }

463-499: Add HTTP timeouts and ensure disconnect/stream cleanup

Prevent resource leaks and hanging connections; also guard null error stream.

-    private void publishEvent(CloudEvent event) {
-        try {
-            URL url = URI.create(brokerUrl).toURL();
-            HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
+    private void publishEvent(CloudEvent event) {
+        HttpURLConnection httpUrlConnection = null;
+        try {
+            URL url = URI.create(brokerUrl).toURL();
+            httpUrlConnection = (HttpURLConnection) url.openConnection();
             httpUrlConnection.setRequestMethod("POST");
             httpUrlConnection.setDoOutput(true);
             httpUrlConnection.setDoInput(true);
+            httpUrlConnection.setConnectTimeout(5000);
+            httpUrlConnection.setReadTimeout(10000);
@@
-            int responseCode = httpUrlConnection.getResponseCode();
+            int responseCode = httpUrlConnection.getResponseCode();
             logger.info("Broker response code: {}", responseCode);
@@
-                String errorResponse = "";
-                try {
-                    errorResponse = new String(httpUrlConnection.getErrorStream().readAllBytes());
-                } catch (Exception e) {
-                    // Ignore error reading error stream
-                }
+                String errorResponse = "";
+                try (var es = httpUrlConnection.getErrorStream()) {
+                    if (es != null) {
+                        errorResponse = new String(es.readAllBytes());
+                    }
+                } catch (Exception ignore) {
+                    // ignore
+                }
                 logger.error("Failed to publish event. Response code: {}, Error: {}", responseCode, errorResponse);
                 throw new RuntimeException("Failed to publish event. Response code: " + responseCode);
             }
 
         } catch (Exception e) {
             logger.error("Error publishing event to broker", e);
             throw new RuntimeException("Failed to publish event", e);
+        } finally {
+            if (httpUrlConnection != null) {
+                httpUrlConnection.disconnect();
+            }
         }
     }

767-789: Move delivery block under spec (not subscriber)

Current placement is invalid and will be ignored.

 spec:
   broker: default
   filter:
     attributes:
       type: com.example.order.placed
   subscriber:
     ref:
       apiVersion: v1
       kind: Service
       name: order-processor
-    delivery:
-      deadLetterSink:
-        ref:
-          apiVersion: v1
-          kind: Service
-          name: dead-letter-service
-      retry: 3
+  delivery:
+    deadLetterSink:
+      ref:
+        apiVersion: v1
+        kind: Service
+        name: dead-letter-service
+    retry: 3
🧹 Nitpick comments (8)
.gitignore (1)

1-17: Optional: Add a few common OS/editor ignores.

Consider also ignoring Windows and IDE artifacts to reduce churn:

  • Thumbs.db
  • .idea/ (JetBrains)
  • .vscode/ (workspace settings, only if not intentionally shared)

Proposed patch:

+.idea/
+.vscode/
+Thumbs.db
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (7)

128-128: Grammar nit: “Let’s”

Use the contraction.

-Lets create a simple HTTP service that receives and output events as logs:
+Let's create a simple HTTP service that receives and outputs events as logs:

239-239: Consistent naming: “Spring Boot”

Align heading with standard spelling used elsewhere in the doc.

-## Chapter 3. Enabling SpringBoot Applications for Cloud Events
+## Chapter 3. Enabling Spring Boot Applications for Cloud Events

294-294: Remove unused import

java.util.Map isn’t used.

-import java.util.Map;

679-679: Unify broker ingress hostname across docs

Earlier examples use knative-operator; this env var uses knative-eventing. Pick one to avoid confusion. Below aligns to earlier “kubectl get broker” URL.

-          value: "http://broker-ingress.knative-eventing.svc.cluster.local/my-app-namespace/default"
+          value: "http://broker-ingress.knative-operator.svc.cluster.local/my-app-namespace/default"

If your cluster exposes broker-ingress via knative-eventing instead, switch the earlier examples to match. Please confirm which is correct for ACP v3.


695-695: Consistent naming: “Spring Boot”

Fix heading.

-### Testing the SpringBoot Application
+### Testing the Spring Boot Application

699-705: Make curl test workable from a developer machine

Add port-forward so the service is reachable; then curl localhost.

-   curl -X POST http://springboot-event-app/api/users \
+   kubectl -n my-app-namespace port-forward svc/springboot-event-app 8080:80
+   curl -X POST http://localhost:8080/api/users \
      -H "Content-Type: application/json" \
      -d '{"email": "user@example.com"}'

401-405: Property vs env var mapping sanity check

You use @value("knative.broker.url") with a default and also set KNATIVE_BROKER_URL via env. Spring Boot will map KNATIVE_BROKER_URL → knative.broker.url (OK). Ensure the value matches the earlier Broker URL and avoid drift between application.yml and the Deployment env var.

Also applies to: 567-574, 679-679

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c74d683 and a2a699b.

⛔ Files ignored due to path filters (3)
  • docs/public/KB250700002/knative-eventing.png is excluded by !**/*.png
  • package-lock.json is excluded by !**/package-lock.json
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md

28-28: Images should have alternate text (alt text)

(MD045, no-alt-text)


750-750: Hard tabs
Column: 1

(MD010, no-hard-tabs)


751-751: Hard tabs
Column: 1

(MD010, no-hard-tabs)


752-752: Hard tabs
Column: 1

(MD010, no-hard-tabs)


753-753: Hard tabs
Column: 1

(MD010, no-hard-tabs)

🔇 Additional comments (3)
.gitignore (2)

16-16: Good addition: .DS_Store

Ignoring macOS .DS_Store files prevents noisy diffs on mac machines. Looks good.


15-15: Confirm dist generation prior to Docker build — Dockerfile copies dist/ (lines 3–5) but .gitignore excludes it, so ensure your CI or local workflow runs doom build (or equivalent) to populate dist before docker build.

docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (1)

741-759: Fix YAML formatting, typo, and filter syntax

• Replace tabs with spaces
• Fix typo amoundamount
• Indent filters correctly for - all: with nested - exact: and - suffix:

 spec:
   broker: default
-  filters:
-    - all:
-        - exact:
-            type: com.example.order.placed
-        - suffix:
-            amount: "1000"  # Filter for amound suffixed attributes equals to 1000
+  filters:
+    - all:
+        - exact:
+            type: com.example.order.placed
+        - suffix:
+            amount: "1000"  # Filter for events whose 'amount' extension ends with "1000"

Confirm your Knative Eventing version supports spec.filters (alpha behind the new-trigger-filters feature gate); if not, use the legacy spec.filter.attributes syntax or a CEL filter workaround.

Copy link
Copy Markdown

@tik-seven tik-seven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前期已验证KB中核心功能,本次本地预览格式内容无问题。

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (5)
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (5)

28-28: Add descriptive alt text to image (accessibility)
Missing alt text violates MD045 and hurts accessibility.

Apply:

-![](/KB250700002/knative-eventing.png)
+![Knative Eventing architecture diagram showing producers, broker, triggers, and consumers](/KB250700002/knative-eventing.png)

281-321: Avoid NPE on event.getData() and drop unused import
Directly dereferencing event.getData() may NPE; JsonFormat import is unused.

Apply:

-import io.cloudevents.jackson.JsonFormat;
@@
-            logger.info("  Data: {}", new String(event.getData().toBytes()));
+            if (event.getData() != null) {
+                logger.info("  Data: {}", new String(event.getData().toBytes(), java.nio.charset.StandardCharsets.UTF_8));
+            } else {
+                logger.info("  Data: <none>");
+            }

463-499: Add HTTP timeouts and always disconnect to avoid resource leaks
No timeouts and missing disconnect can hang or leak connections.

Apply:

-    private void publishEvent(CloudEvent event) {
-        try {
-            URL url = URI.create(brokerUrl).toURL();
-            HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
+    private void publishEvent(CloudEvent event) {
+        HttpURLConnection httpUrlConnection = null;
+        try {
+            URL url = URI.create(brokerUrl).toURL();
+            httpUrlConnection = (HttpURLConnection) url.openConnection();
             httpUrlConnection.setRequestMethod("POST");
             httpUrlConnection.setDoOutput(true);
             httpUrlConnection.setDoInput(true);
+            httpUrlConnection.setConnectTimeout(5000);
+            httpUrlConnection.setReadTimeout(10000);
@@
-                String errorResponse = "";
-                try {
-                    errorResponse = new String(httpUrlConnection.getErrorStream().readAllBytes());
-                } catch (Exception e) {
-                    // Ignore error reading error stream
-                }
+                String errorResponse = "";
+                try (java.io.InputStream es = httpUrlConnection.getErrorStream()) {
+                    if (es != null) {
+                        errorResponse = new String(es.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
+                    }
+                } catch (Exception e) {
+                    // Ignore error reading error stream
+                }
@@
-        } catch (Exception e) {
+        } catch (Exception e) {
             logger.error("Error publishing event to broker", e);
             throw new RuntimeException("Failed to publish event", e);
+        } finally {
+            if (httpUrlConnection != null) {
+                httpUrlConnection.disconnect();
+            }
         }
     }

Also applies to the same method’s error-stream handling pattern below.


741-759: Fix YAML: tabs, typo, and suffix filter syntax (and confirm feature gate)
Tabs make YAML invalid; amound is a typo; ensure suffix value is a quoted string and indentation is valid.

Apply:

 spec:
   broker: default
-  filters:
-  - all:
-	- exact:
-	      type: com.example.order.placed
-	- suffix:
-	    amount: "1000"  # Filter for amound suffixed attributes equals to 1000
+  filters:
+    - all:
+        - exact:
+            type: com.example.order.placed
+        - suffix:
+            amount: "1000"  # Filter for events whose string 'amount' extension ends with "1000"
   subscriber:
     ref:
       apiVersion: v1
       kind: Service
       name: high-value-order-processor

Ensure new-trigger-filters is enabled on your Knative version; otherwise switch to spec.filter.attributes or CEL.


767-789: Place delivery under spec, not subscriber
delivery under subscriber is invalid; move it to spec.delivery.

Apply:

 spec:
   broker: default
   filter:
     attributes:
       type: com.example.order.placed
   subscriber:
     ref:
       apiVersion: v1
       kind: Service
       name: order-processor
-    delivery:
-      deadLetterSink:
-        ref:
-          apiVersion: v1
-          kind: Service
-          name: dead-letter-service
-      retry: 3
+  delivery:
+    deadLetterSink:
+      ref:
+        apiVersion: v1
+        kind: Service
+        name: dead-letter-service
+    retry: 3
🧹 Nitpick comments (2)
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (2)

401-403: Align broker ingress host consistently
Two different broker ingress hosts are used (knative-operator vs knative-eventing). Pick one that matches your install to avoid misroutes.

Example (adjust to your cluster):

-          value: "http://broker-ingress.knative-eventing.svc.cluster.local/my-app-namespace/default"
+          value: "http://broker-ingress.knative-operator.svc.cluster.local/my-app-namespace/default"

Note: Spring Boot will map KNATIVE_BROKER_URL -> knative.broker.url via relaxed binding.

Also applies to: 677-680


128-128: Minor wording/typo fixes in user-facing text
Improves clarity and consistency.

Apply:

-Lets create a simple HTTP service that receives and output events as logs:
+Let's create a simple HTTP service that receives events and outputs them to logs:
-          # Change to inhouse registry address and image
+          # Change to in-house registry address and image
-## Chapter 3. Enabling SpringBoot Applications for Cloud Events
+## Chapter 3. Enabling Spring Boot Applications for CloudEvents
-For this part we will still build uppon the EventConsumer created on the last part.
+For this part, we'll build upon the EventConsumer created in the previous section.
-### Testing the SpringBoot Application
+### Testing the Spring Boot application

Also applies to: 147-147, 238-239, 363-365, 695-695

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2a699b and 42d4100.

⛔ Files ignored due to path filters (1)
  • docs/public/KB250700002/knative-eventing.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .gitignore
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md

28-28: Images should have alternate text (alt text)

(MD045, no-alt-text)


750-750: Hard tabs
Column: 1

(MD010, no-hard-tabs)


751-751: Hard tabs
Column: 1

(MD010, no-hard-tabs)


752-752: Hard tabs
Column: 1

(MD010, no-hard-tabs)


753-753: Hard tabs
Column: 1

(MD010, no-hard-tabs)

Comment on lines +177 to +192
```yaml
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: ping-trigger
namespace: my-app-namespace
spec:
broker: default
# empty filters means all events will be sent to the subscriber
filters: []
subscriber:
ref:
apiVersion: v1
kind: Service
name: event-display
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

❓ Verification inconclusive

Use stable Trigger filter field (avoid alpha-only spec.filters)
spec.filters: [] relies on an alpha feature gate; prefer stable spec.filter (or omit filter) so “match all” works across installs.

Apply:

 spec:
   broker: default
-  # empty filters means all events will be sent to the subscriber
-  filters: []
+  # no filter means all events will be sent to the subscriber (stable API)
+  filter: {}
   subscriber:
     ref:
       apiVersion: v1
       kind: Service
       name: event-display

And adjust docs:

-- `spec.filters`: Defines filtering criteria for events
+- `spec.filter`: Defines filtering criteria for events

If you do want the new multi-filter syntax, confirm the new-trigger-filters feature gate is enabled in your Knative cluster and version supports it.

Also applies to: 200-205


Use stable Trigger filter (avoid alpha-only spec.filters)
spec.filters requires the new-trigger-filters alpha feature gate (k8s-docs.github.io); switch to the stable spec.filter (or omit it) so match-all works universally (knative.dev).
In docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (177–192, 200–205) apply:

 spec:
   broker: default
-  # empty filters means all events will be sent to the subscriber
-  filters: []
+  # no filter means all events will be sent to the subscriber (stable API)
+  filter: {}

Update all occurrences of spec.filters to spec.filter.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```yaml
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: ping-trigger
namespace: my-app-namespace
spec:
broker: default
# empty filters means all events will be sent to the subscriber
filters: []
subscriber:
ref:
apiVersion: v1
kind: Service
name: event-display
```
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: ping-trigger
namespace: my-app-namespace
spec:
broker: default
# no filter means all events will be sent to the subscriber (stable API)
filter: {}
subscriber:
ref:
apiVersion: v1
kind: Service
name: event-display
🤖 Prompt for AI Agents
In
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md
around lines 177–192 (and also check 200–205), update the Trigger examples and
any narrative that use the alpha-only field name `spec.filters` to the stable
field `spec.filter` (or remove the filter stanza entirely to indicate a
match-all behavior); ensure the YAML and text consistently reference
`spec.filter` and, if keeping an explicit match-all, use `spec.filter: []` or
omit the field per Knative docs so it works without the alpha feature gate.

Comment on lines +245 to +268
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-core</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-http-basic</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-json-jackson</artifactId>
<version>2.5.0</version>
</dependency>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Confirm CloudEvents Java SDK versions
Pinned to 2.5.0; verify latest stable to avoid CVEs/bugs.


🌐 Web query:

What is the latest stable version of the CloudEvents Java SDK modules (cloudevents-core, cloudevents-http-basic, cloudevents-json-jackson) as of September 2025?

💡 Result:

Checked Sep 9, 2025 — latest stable versions on Maven Central:

  • cloudevents-core: 4.0.1. [1]
  • cloudevents-http-basic: 4.0.1. [2]
  • cloudevents-json-jackson: 4.0.1. [3]

Sources: Maven Central listings for each artifact. [1] (mvnrepository.com) [2] (mvnrepository.com) [3] (mvnrepository.com)

Citations:


Upgrade CloudEvents Java SDK dependencies to latest stable (4.0.1)
In docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md (lines 245–268), update cloudevents-core, cloudevents-http-basic, and cloudevents-json-jackson from 2.5.0 to 4.0.1 cite123

🤖 Prompt for AI Agents
In
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md
around lines 245 to 268, the CloudEvents Java SDK dependencies
(cloudevents-core, cloudevents-http-basic, cloudevents-json-jackson) are pinned
to 2.5.0; update each of these dependency version tags from 2.5.0 to 4.0.1 in
the dependency block so the docs reflect the latest stable SDK version.

Comment on lines +437 to +454
public void publishOrderPlacedEvent(String orderId, String customerId, double amount) {
try {
// Create event data
OrderPlacedData eventData = new OrderPlacedData(orderId, customerId, amount);

// Serialize event data to JSON
String eventDataJson = objectMapper.writeValueAsString(eventData);
byte[] eventDataBytes = eventDataJson.getBytes();

// Build CloudEvent
CloudEvent event = CloudEventBuilder.v1()
.withId(UUID.randomUUID().toString())
.withType("com.example.order.placed")
.withSource(URI.create("https://example.com/order-service"))
.withTime(OffsetDateTime.now())
.withData("application/json", eventDataBytes)
.build();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make suffix-based Trigger example actually match by adding 'amount' extension
Your later Trigger filters on the string extension attribute amount, but the event sets amount only in the data payload. Expose it as an extension for the example to work.

Apply:

             CloudEvent event = CloudEventBuilder.v1()
                     .withId(UUID.randomUUID().toString())
                     .withType("com.example.order.placed")
                     .withSource(URI.create("https://example.com/order-service"))
                     .withTime(OffsetDateTime.now())
+                    // expose 'amount' as string extension for Trigger suffix filter
+                    .withExtension("amount", String.valueOf(amount))
                     .withData("application/json", eventDataBytes)
                     .build();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void publishOrderPlacedEvent(String orderId, String customerId, double amount) {
try {
// Create event data
OrderPlacedData eventData = new OrderPlacedData(orderId, customerId, amount);
// Serialize event data to JSON
String eventDataJson = objectMapper.writeValueAsString(eventData);
byte[] eventDataBytes = eventDataJson.getBytes();
// Build CloudEvent
CloudEvent event = CloudEventBuilder.v1()
.withId(UUID.randomUUID().toString())
.withType("com.example.order.placed")
.withSource(URI.create("https://example.com/order-service"))
.withTime(OffsetDateTime.now())
.withData("application/json", eventDataBytes)
.build();
public void publishOrderPlacedEvent(String orderId, String customerId, double amount) {
try {
// Create event data
OrderPlacedData eventData = new OrderPlacedData(orderId, customerId, amount);
// Serialize event data to JSON
String eventDataJson = objectMapper.writeValueAsString(eventData);
byte[] eventDataBytes = eventDataJson.getBytes();
// Build CloudEvent
CloudEvent event = CloudEventBuilder.v1()
.withId(UUID.randomUUID().toString())
.withType("com.example.order.placed")
.withSource(URI.create("https://example.com/order-service"))
.withTime(OffsetDateTime.now())
// expose 'amount' as string extension for Trigger suffix filter
.withExtension("amount", String.valueOf(amount))
.withData("application/json", eventDataBytes)
.build();
🤖 Prompt for AI Agents
In
docs/en/solutions/Leveraging_Knative_Eventing_for_Cloud_Event_Publishing_and_Consuming.md
around lines 437 to 454, the CloudEvent is built without exposing the numeric
amount as an extension even though the Trigger later filters on the string
extension attribute "amount"; add an extension to the CloudEvent (e.g., call the
CloudEvent builder's withExtension("amount", String.valueOf(amount)) or
equivalent) before build so the Trigger's suffix-based filter matches the event.

@tik-seven tik-seven merged commit 0023e2f into main Sep 10, 2025
2 checks passed
@tik-seven tik-seven deleted the chore/move-knative-kb branch September 10, 2025 01:37
changluyi pushed a commit to changluyi/knowledge that referenced this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants